<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div class="div1"></div>
    <div class="div2"></div>
    <script>
        let obj = {
        };

        Object.defineProperty(obj,"name",{
            // 设置值
            value: "奉先",
            // 属性可以删除（默认false）
            configurable: true,
            // 可以遍历（默认false）
            enumerable: true,
            // 属性值可以被修改（默认false）
            writable: true,

        })

        Object.defineProperty(obj,"text",{
            set(value) {
                let div1 = document.querySelector(".div1");
                div1.innerText = value;
                text = value;
            },
            get() {
                return text;
            }
        });

        Object.defineProperty(obj,"message",{
            set(value) {
                let div2 = document.querySelector(".div2");
                div2.innerText = value;
                message = value;
            },
            get() {
                return message;
            },
            enumerable: true,
        });

        obj.text = "123";
        obj.message = "234";

        obj.name = "234";
        console.log(obj.name);

        let keys = Object.keys(obj);
        console.log("keys = ",keys); // ["name","message"]



    </script>
</body>
</html>